<?php
    
        
    
    
    //$url ="http://www.webucator.com/mobile-training/index.cfm";
    //$url = "http://www.webucator.com/java/index.cfm";
    
    //$courseSelected = "java";
        
    //echo (validate($url,$courseSelected)) ? "valid url :".$url : "invalid url :".$url;
    //echo "</br>";
    
    
    
    function validate($url,$courseSelected) {
        
        
        $countValidPolicy=0;
        @$page = file_get_contents($url);
        //echo "PAge is ".$page;
        $replacedCount = 0;
        $pageArray = explode("\n", $page);
        $outArray = array();
        foreach ($pageArray as $line) {
            
            $line = preg_replace("/<a href=.*>(.*?)<\/a>/i", "", $line);
            array_push($outArray, $line);
        }
        
        $page = implode("\n", $outArray);
        //echo "page after implode".$page;
        $policy = array ();
        $policy[0]= "|\b$courseSelected\b|i";
        $policy[1]="|\\bcourse\\b|i";
        $policy[2]="|\\btraining\\b|i";
        //$policy[3]="|\\bprogramming\\b|i";
        //$policy[4]="|\\blanguage\\b|i";
        //$policy[5]="|\\blearning\\b|i";
        //$policy[6]="|\\bonline\\b|i";
        
        $countPolicy = count($policy);
                
        //echo "No of replaced .....".$replacedCount;
        foreach ($policy as $value){
            
            if (preg_match($value,$page,$matches)){
                //echo "Match for ".$matches[0];
                $countValidPolicy++;
            }
            else {
                //echo "Did not find match for ".$value;
                $j++;
            }
        }
        
        
        
        
        if ( $countValidPolicy== $countPolicy ){
            //echo "valid url"."</br>";
            //echo $validity."</br>";
            $valid = true ;
            
        }
        else{
            //echo "invalid url";
            $valid = false;
        }
        
        return $valid;
    
        
    }
        
                

    
?>
        

